//
//  SDSyndromeCell.m
//  SuperDoctor
//
//  Created by 李忠 on 7/12/16.
//  Copyright © 2016 SD. All rights reserved.
//

#import "SDSyndromeCell.h"

@interface SDSyndromeCell ()


@property (nonatomic, weak) UIButton *btn_Subscribe;


@end

@implementation SDSyndromeCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (void)setModel:(SDSubdivideModel *)model{
    _model = model;
    self.textLabel.text = model.ci3_name;
    _btn_Subscribe.selected = model.isSelected;
    
    
    
}

- (void)setupUI{
    UIButton *btn = [[UIButton alloc] init];
    _btn_Subscribe = btn;
    [self.contentView addSubview:_btn_Subscribe];
    [btn setTitle:@"订阅" forState:UIControlStateNormal];
    [btn setTitle:@"已订阅" forState:UIControlStateSelected];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
    btn.layer.cornerRadius = 3;
    btn.layer.masksToBounds = YES;
    btn.backgroundColor = kThemeColor;
    [btn addTarget:self action:@selector(clickCellButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.trailing.mas_offset(-10);
        make.width.mas_equalTo(80);
        
    }];

}

- (void)clickCellButton:(UIButton *)sender{
    
    sender.selected = !sender.isSelected;
    
    if (sender.isSelected) {
        
        self.model.selected = YES;
        NSString *name = self.model.ci3_name;
        [self.diseaseArrM addObject:name];
    }else{
        self.model.selected = NO;
        NSString *name = self.model.ci3_name;
        [self.diseaseArrM removeObject:name];
    }
    
}
@end
